package com.example.shilehui;



import cn.jhc.service.DonatePlanService;
import cn.jhc.utils.SharedMethod;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

public class DonatePlanHandyActivity extends Activity {

	
	
	private TextView _titleLeftTextView;
	private TextView _titleRightTextView;
	private TextView _titleMiddleTextView;
	private EditText _editText;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		ini();
	}
	
	private void ini(){
		
		setContentView(R.layout.donate_plan_enter_handy_layout);
		setTitleStyle();
		setPageStyle();
		
	}
	
	private void setTitleStyle(){
		_titleLeftTextView=(TextView)findViewById(R.id.user_login_title_left_text);
		_titleMiddleTextView=(TextView)findViewById(R.id.user_login_title_middle);
		_titleRightTextView=(TextView)findViewById(R.id.user_login_title_right_text);
		
		_titleLeftTextView.setText(getResources().getString(R.string.close));
		_titleLeftTextView.setTextColor(Color.WHITE);
		_titleLeftTextView.setTextSize(16);
		_titleMiddleTextView.setText(getResources().getString(R.string.donate_plan_enter_handy));	
		_titleMiddleTextView.setTextColor(Color.WHITE);
		_titleMiddleTextView.setTextSize(18);
		_titleRightTextView.setText(getResources().getString(R.string.confirm));
		_titleRightTextView.setTextColor(Color.WHITE);
		_titleRightTextView.setTextSize(16);
		
		_titleRightTextView.setOnClickListener(new OnTitleClickListener());
		_titleLeftTextView.setOnClickListener(new OnTitleClickListener());
		
	}
	
	private void setPageStyle(){
		
		_editText=(EditText)findViewById(R.id.donate_plan_handy_edittext);
		_editText.setTextColor(Color.BLACK);
		
		
	}
	
	private class OnTitleClickListener implements OnClickListener{

		@Override
		public void onClick(View v) {
			
			switch (v.getId()) {
			case R.id.user_login_title_left_text:
				finish();
				break;
				
			case R.id.user_login_title_right_text:
				
				String text=_editText.getText().toString();
				if(isTextValid()){
					DonatePlanService.getInstance().setPhoneNumber(text);
					finish();
				}else{
					SharedMethod.getInstance().showAlertDialog(DonatePlanHandyActivity.this, getResources().getString(R.string.enter_wrong));
					
				}
				break;
			default:
				break;
			}
		}	
	}
	
	private boolean isTextValid(){
		
		String text=_editText.getText().toString();
		
		if(text!=""){
			if(SharedMethod.getInstance().isNumber(text)){
				return true;
			}
		}
		
		return false;
	}
	

}
